package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.base.domain.User;
import cn.wolfcode.car.base.service.IUserService;
import cn.wolfcode.car.base.service.impl.UserServiceImpl;
import cn.wolfcode.car.business.domain.BpmnInfo;
import cn.wolfcode.car.business.domain.Leave;
import cn.wolfcode.car.business.domain.ServiceItem;
import cn.wolfcode.car.business.query.LeaveQuery;
import cn.wolfcode.car.business.service.IBpmnInfoService;
import cn.wolfcode.car.business.service.ILeaveService;
import cn.wolfcode.car.business.vo.ServiceItemAuditVO;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 结算单 控制器
 */
@Controller
@RequestMapping("business/leave")
public class LeaveController {
    //模板前缀
    private static final String prefix = "business/leave/";

    @Autowired
    private ILeaveService leaveService;
    @Autowired
    private IUserService userService;
    @Autowired
    private IBpmnInfoService bpmnInfoService;



    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:leave:view")
    @RequestMapping("/listPage")
    public String listPage(){
        return prefix + "list";
    }

    // 发起审核
    @RequestMapping("/startAuditPage")
    public String startAuditPage(Model model){

        // 把系统中店长财务专员查询出来(根据画的图来查询审核人)
        List<User> directors = userService.queryByRoleKey("shopOwner");
        List<User> finances = userService.queryByRoleKey("financial");
        model.addAttribute("directors",directors);
        model.addAttribute("finances",finances);


        // 把bpmnInfo 查询出来,然后放到作用域中
        List<BpmnInfo> bpmnInfos = bpmnInfoService.queryByType("casual-leave");
        model.addAttribute("bpmnInfos",bpmnInfos.get(0));
        return prefix + "audit";
    }




    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:leave:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<Leave> query(LeaveQuery qo){
        return leaveService.query(qo);
    }




    // 发起审核
    @RequestMapping("/startAudit")
    @ResponseBody
    public AjaxResult startAudit(ServiceItemAuditVO vo){
        leaveService.startAudit(vo);
        return AjaxResult.success();
    }





}
